#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    pid_t p_child, p_wait;

    p_child = fork();
    if(p_child < 0) {
      printf("create fork fail\n");
      exit(1);
    }
    else if(p_child == 0) {
      printf("i am child process,my pid is %d\n", getpid());
      sleep(3);
      exit(0);
    }
    else {
      printf("now in parent process,my pid is %d\n", getpid());
      printf("i am waiting child process to exit.\n");
      p_wait = wait(NULL);
      if(p_wait > 0) {
        printf("i catch a child process exit with pid is %d.\n", p_wait);
      }
      else {
        printf("error:%s\n", strerror(errno));
      }
    }

    exit(0);
}
